package com.istock.http;

import java.util.List;
import java.util.Map;

import org.apache.commons.lang3.builder.ToStringBuilder;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.istock.base.common.api.model.ApiBaseResponse;
import com.istock.base.common.api.model.RetStatusEnum;

/**用于讲解springMVC传参的示例
 * 对于不同的controller的参数,spring是如何进行传参的
 * 
 * 本示例也是HttpService的示例,这边不能实现HttpMock接口,如果实现,spring的autoWired注入会失败,spring容器内会出现2个HttpMock的实例
 * @author Administrator
 *
 */
@Controller
@RequestMapping("httpMock")
public class HttpServiceController //implements HttpMock
{

	private Logger logger = LoggerFactory.getLogger(getClass());
	@ResponseBody
	@RequestMapping("test1")
	public ApiBaseResponse<String> test1(String requestId){
		logger.info("ready to test1 ================{}" , requestId);
		return new ApiBaseResponse<String>(RetStatusEnum.SUCCESS,"ok" , "ok" , "test1 is ok");
	}
	
	@ResponseBody
	@RequestMapping("test2")
	public ApiBaseResponse<String> test2(ModelTest model , MdoelMock mock){
		logger.info("ready to test2 ================{},{}" , ToStringBuilder.reflectionToString(model) , ToStringBuilder.reflectionToString(mock));
		return new ApiBaseResponse<String>(RetStatusEnum.SUCCESS,"ok" , "ok" , "test2 is ok");
	}
	
	@ResponseBody
	@RequestMapping("test3")
	public ApiBaseResponse<String> test3(@RequestBody Map<String , Object> paramMap){
		logger.info("ready to test3 ================{}" , paramMap);
		return new ApiBaseResponse<String>(RetStatusEnum.SUCCESS,"ok" , "ok" , "test3 is ok");
	}
	
	@ResponseBody
	@RequestMapping("test4")
	public ApiBaseResponse<String> test4(@RequestBody List<ModelTest> modelList){
		logger.info("ready to test4 ================{}" ,  ToStringBuilder.reflectionToString(modelList));
		return new ApiBaseResponse<String>(RetStatusEnum.SUCCESS,"ok" , "ok" , "test4 is ok");
	}
	
	@ResponseBody
	@RequestMapping("test5")
	public ApiBaseResponse<String> test5(Integer[] numberList){
		logger.info("ready to test5 ================{}" , ToStringBuilder.reflectionToString(numberList));
		return new ApiBaseResponse<String>(RetStatusEnum.SUCCESS,"ok" , "ok" , "test5 is ok");
	}
}
